
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author leehoa
 */
public class compareTime {
    
    public static void main(String [] agr) throws Exception{
        
        SimpleDateFormat parser = new SimpleDateFormat("HH:mm");
        Date ten = parser.parse("10:00");
        Date eighteen = parser.parse("18:00");
        Date now = new Date();                        
        try {
            Date userDate = parser.parse("22:00");
            if (userDate.after(ten) && userDate.before(eighteen)) {
                System.out.println("ok");
            }else
                System.err.println("fail");
            
            boolean flag = checkTimeZone("GMT","08:00","18:00");
            if(flag)
                System.err.println("check OK");
            else
                System.err.println("check fail");
            
        } catch (ParseException e) {
            // Invalid date was entered
        }        
    }
    
    public static boolean checkTimeZone(String timezone, String min, String max){
        try{
            Date date = new Date();
            SimpleDateFormat simpDate = new SimpleDateFormat("kk:mm");
            simpDate.setTimeZone(TimeZone.getTimeZone(timezone));              
            String time = simpDate.format(date);
            date = simpDate.parse(time);
            Date minDate = simpDate.parse(min);
            Date maxDate = simpDate.parse(max);
            if(date.after(minDate) && date.before(maxDate))
                return true;            
            System.out.println("timezone: "+simpDate.format(date));
        }catch(Exception ex){
            return false;
        }
        return false;
    }    
    
}
